{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "962a60f8",
   "metadata": {},
   "source": [
    "## 本周内容"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2ce38548",
   "metadata": {},
   "source": [
    ">1.人脸对比       \n",
    ">2.人脸搜索"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "edd4ea33",
   "metadata": {},
   "source": [
    "## 人脸对比"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "be90b50d",
   "metadata": {},
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "invalid syntax (3442896777.py, line 13)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;36m  Input \u001b[1;32mIn [3]\u001b[1;36m\u001b[0m\n\u001b[1;33m    f_01 = open('wyf.jpg','rb'.)\u001b[0m\n\u001b[1;37m                               ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid syntax\n"
     ]
    }
   ],
   "source": [
    "# encoding:utf-8\n",
    "\n",
    "import requests\n",
    "import base64\n",
    "\n",
    "'''\n",
    "Face++\n",
    "'''\n",
    "\n",
    "request_url = \"https://api-cn.faceplusplus.com/facepp/v3/compare\"\n",
    "# 二进制方式打开图片文件\n",
    "# 1.\n",
    "f_01 = open('wyf.jpg','rb'.)\n",
    "f_02 = open('wyf_02.jpg','rb'.)\n",
    "img_01 = base64.b64encode(f.read())\n",
    "img_02 = base64.b64encode(f.read())\n",
    "\n",
    "params = {\n",
    "     \"api_key\":\"PLyz3qFkk5VigBhtbVRH0O6tTU_LDcDN\",\n",
    "    \"api_secret\":\"CLhFqVzrLbuIEBpKaiejCFneU2Yon_HT\",\n",
    "    \"image_base64_1\":img_01,\n",
    "    \"image_base64_2\":img_02,\n",
    "\n",
    "\n",
    "headers = {'content-type': 'application/x-www-form-urlencoded'}\n",
    "response = requests.post(request_url, data=payload, headers=headers)\n",
    "\n",
    "    print(response.json())\n",
    "    print(response.status_code)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "facf55c5",
   "metadata": {},
   "source": [
    "# 2.人脸搜索"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "74bf1673",
   "metadata": {},
   "source": [
    "## 2.1 人脸库管理"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b5a70e41",
   "metadata": {},
   "source": [
    "## 2.1.1创建人脸数据集"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "c9df4e8c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "200\n",
      "{'faceset_token': '01b44531a50304da336fb75cc837658c', 'time_used': 193, 'face_count': 0, 'face_added': 0, 'request_id': '1679283558,a2e0cabc-37c4-4e35-9037-07c6a9eefa9e', 'outer_id': '', 'failure_detail': []}\n"
     ]
    }
   ],
   "source": [
    "# encoding:utf-8\n",
    "\n",
    "import requests\n",
    "\n",
    "'''\n",
    "Face++\n",
    "'''\n",
    "request_url = \"https://api-cn.faceplusplus.com/facepp/v3/faceset/create\"\n",
    "#请求参数\n",
    "params = {\n",
    "     \"api_key\":\"PLyz3qFkk5VigBhtbVRH0O6tTU_LDcDN\",\n",
    "     \"api_secret\":\"CLhFqVzrLbuIEBpKaiejCFneU2Yon_HT\",\n",
    "    \"dispaly_name\":\"广州南方学院1栋宿舍楼\"\n",
    "    \n",
    "   \n",
    "}\n",
    "\n",
    "response = requests.post(request_url, data=params)\n",
    "\n",
    "print(response.status_code)\n",
    "print(response.json())"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "11006a0d",
   "metadata": {},
   "source": [
    "## 2.1.2检查人脸数据集的情况"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "a9030f79",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "200\n",
      "{'faceset_token': '77dfacd96ce231e2bbd096752c940296', 'time_used': 171, 'face_count': 0, 'face_added': 0, 'request_id': '1679283572,409d62dd-155c-4cad-8d3f-5a22e64c4bd4', 'outer_id': '', 'failure_detail': []}\n"
     ]
    }
   ],
   "source": [
    "# encoding:utf-8\n",
    "\n",
    "import requests\n",
    "\n",
    "'''\n",
    "Face++\n",
    "'''\n",
    "request_url = \"https://api-cn.faceplusplus.com/facepp/v3/faceset/create\"\n",
    "#请求参数\n",
    "params = {\n",
    "     \"api_key\":\"PLyz3qFkk5VigBhtbVRH0O6tTU_LDcDN\",\n",
    "     \"api_secret\":\"CLhFqVzrLbuIEBpKaiejCFneU2Yon_HT\",\n",
    "   \"faceset_token\": \"01b44531a50304da336fb75cc837658c\",\n",
    "    \n",
    "   \n",
    "}\n",
    "\n",
    "response = requests.post(request_url, data=params)\n",
    "\n",
    "print(response.status_code)\n",
    "print(response.json())"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "156edf01",
   "metadata": {},
   "source": [
    "## 2.1.3 增加人脸数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "b9b881d9",
   "metadata": {},
   "outputs": [
    {
     "ename": "FileNotFoundError",
     "evalue": "[Errno 2] No such file or directory: '1栋/yqw.jpg'",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mFileNotFoundError\u001b[0m                         Traceback (most recent call last)",
      "Input \u001b[1;32mIn [5]\u001b[0m, in \u001b[0;36m<cell line: 14>\u001b[1;34m()\u001b[0m\n\u001b[0;32m     12\u001b[0m request_url \u001b[38;5;241m=\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mhttps://api-cn.faceplusplus.com/facepp/v3/detect\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[0;32m     13\u001b[0m \u001b[38;5;66;03m# 二进制方式打开图片文件\u001b[39;00m\n\u001b[1;32m---> 14\u001b[0m f \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mopen\u001b[39;49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43m1栋/yqw.jpg\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mrb\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m)\u001b[49m\n\u001b[0;32m     16\u001b[0m img \u001b[38;5;241m=\u001b[39m base64\u001b[38;5;241m.\u001b[39mb64encode(f\u001b[38;5;241m.\u001b[39mread())\n\u001b[0;32m     19\u001b[0m params \u001b[38;5;241m=\u001b[39m {\n\u001b[0;32m     20\u001b[0m     \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mapi_key\u001b[39m\u001b[38;5;124m\"\u001b[39m:\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m0-ePdEz8tHKevHo9diua4pfotiecQc5X\u001b[39m\u001b[38;5;124m\"\u001b[39m,\n\u001b[0;32m     21\u001b[0m     \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mapi_secret\u001b[39m\u001b[38;5;124m\"\u001b[39m:\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mTgtmpFrb2Hmwr6gDpbBV8XBPC9ezB5YD\u001b[39m\u001b[38;5;124m\"\u001b[39m,\n\u001b[0;32m     22\u001b[0m     \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mimage_base64\u001b[39m\u001b[38;5;124m\"\u001b[39m:img,\n\u001b[0;32m     23\u001b[0m \n\u001b[0;32m     24\u001b[0m }\n",
      "\u001b[1;31mFileNotFoundError\u001b[0m: [Errno 2] No such file or directory: '1栋/yqw.jpg'"
     ]
    }
   ],
   "source": [
    "# 先检测人脸信息\n",
    "\n",
    "# encoding:utf-8\n",
    "\n",
    "import requests\n",
    "import base64\n",
    "\n",
    "'''\n",
    "人脸检测: 池昌旭、李钟硕、余庆伟\n",
    "'''\n",
    "\n",
    "request_url = \"https://api-cn.faceplusplus.com/facepp/v3/detect\"\n",
    "# 二进制方式打开图片文件\n",
    "f = open('1栋/yqw.jpg', 'rb')\n",
    "\n",
    "img = base64.b64encode(f.read())\n",
    "\n",
    "\n",
    "params = {\n",
    "    \"api_key\":\"0-ePdEz8tHKevHo9diua4pfotiecQc5X\",\n",
    "    \"api_secret\":\"TgtmpFrb2Hmwr6gDpbBV8XBPC9ezB5YD\",\n",
    "    \"image_base64\":img,\n",
    "\n",
    "}\n",
    "\n",
    "headers = {'content-type': 'application/x-www-form-urlencoded'}\n",
    "response = requests.post(request_url, data=params, headers=headers)\n",
    "print (response.json())\n",
    "print (response.status_code)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2517ca27",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
